﻿$.RS = {
    getString: function (key) {
        return this.entries[key];
    }
};

$.formatstr = function (source, params) {
    if (arguments.length == 1)
        return function () {
            var args = $.makeArray(arguments);
            args.unshift(source);
            return $.format.apply(this, args);
        };
    if (arguments.length > 2 && params.constructor != Array) {
        params = $.makeArray(arguments).slice(1);
    }
    if (params.constructor != Array) {
        params = [params];
    }
    $.each(params, function (i, n) {
        source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
    });
    return source;
};

String.prototype.translate = function () { return $.RS.getString(this); }

// 检查输入的特殊字符串
function CheckInputText(value) {
    if (value.length == 0) {
        return true;
    }
    return !(/<|>|&lt|&gt/).test(value);
}

$().ready(function () {
    /*
    检查不能输入html标记
    Author: 谢韶光
    */
    function CheckHtml(value) {
        return !(/<|>|&lt|&gt/).test(value)
    };

    /*
    检查不能输入html标记
    Author: 谢韶光
    */
    jQuery.validator.addMethod('CheckHtml',
        function (value, element) {
            return this.optional(element) || CheckHtml(value);
        },
        "NoSpecialCharactersHTML".translate()
    //AlertMessages.NoSpecialCharactersHTML
    );

    /*
        检查下拉框是否选择
        Author: 谢韶光
    */
    jQuery.validator.addMethod('CheckSelect',
        function (value, element) {
            return value != "-1" && value != "";
        },
        "PleaseSelect".translate()
    );

    //验证只能输入字母，数字，下划线       
    jQuery.validator.addMethod("stringCheck", function (value, element) {
        return this.optional(element) || /^\w+$/i.test(value);
    },
        "NotAllowedCharacters".translate()
    );
})

reSizeiFrame = function (iframe) {
    if (iframe && !window.opera) {
        iframe.style.display = "block";
        if (iframe.contentDocument && iframe.contentDocument.body.offsetHeight) {
            iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;; //设置iframe在火狐下高度
        }
        else if (iframe.Document && iframe.Document.body.scrollHeight) {
            iframe.height = iframe.Document.body.scrollHeight; //设置iframe在ie下的高度
        }
    }
    iframe.height = iframe.height < 500 ? 500 : iframe.height;
    if ($(iframe).attr("src") != '') {
        window.top.document.getElementById("mainFrame").height = iframe.height;
    }
}

function bodyLoad() {
    exploreResize();
}

/*
浏览器改变大小弹出层自适应方法
Author: liuchuanyong
*/
function exploreResize() {

    try {
        //debugger;
        var formid = $("form").first();
        var scrollHeight = getScrollTop();
        var height = scrollHeight > $('#main_iframe', window.top.document).height() ? scrollHeight : $('#main_iframe', window.top.document).height();
        var width = getScrollLeft() > $('#main_iframe', window.top.document).width() ? $('#main_iframe', window.top.document).width() : getScrollLeft();
        //$("#MyFormLayer").width(width);
        //$(formid).width(width);
        //$(formid).height(height);
        $("#MyFormLayer").width($('#main_iframe', window.top.document).width());
        $("#MyFormLayer").height(height);
    } catch (e) { }
}

/*
js多语言取翻译
Author: 谢韶光
*/
TranslationEntry = function (key) {
    return key.translate();
}

function SetWinHeight(obj) {
    var win = obj;
    if (document.getElementById) {
        if (win && !window.opera) {
            if (win.contentDocument && win.contentDocument.body.offsetHeight)

                win.height = win.contentDocument.body.offsetHeight;
            else if (win.Document && win.Document.body.scrollHeight)
                win.height = win.Document.body.scrollHeight;
        }
        //var width = getScrollLeft() > $('#main_iframe', window.top.document).width() ? $('#main_iframe', window.top.document).width() : getScrollLeft();
        //win.width = width;
    }
}

/*
获取js日期对象 格式：2011-02-23
Author: 谢韶光
*/
parseDate = function (da) {
    if (da == "") {
        return null;
    }
    var yp = da.indexOf('-', 0);
    mp = da.indexOf('-', yp + 1);
    var y = da.substr(0, yp);
    m = da.substr(yp + 1, mp - yp - 1),
    d = da.substr(mp + 1, da.length - mp);
    return new Date(y, m, d);
}

/*
获取js日期对象 2011-02-23
Author: 谢韶光
*/
formatDate = function (d) {
    if (d == "NaN") {
        return "";
    }
    var year = d.getYear();
    if (d.getMonth() == 0) {
        year -= 1;
    }
    return year + "-" + formatDateNum(d.getMonth()) + "-" + formatDateNum(d.getDate());
}
formatDateNum = function (num) {
    if (num == 0) {
        return "12";
    }
    if (num >= 10) {
        return num;
    }
    return "0" + num;
}

/*
设置页面默认控件焦点
Author: 谢韶光
*/
defaultFocus = function (controlId) {
    try {
        $("#" + controlId).focus();
    } catch (e) {
    }
}

function setFrameLocation(url) {
    if (url && url != "")
        url = parseMemberUrl(url);

    $("#mainFrame").attr("src", url);
}

var clientUnity = function () {

    resizeFrame = function () {
        var iframe = window.top.document.getElementById("mainFrame")
        if (iframe && !window.opera) {
            iframe.style.display = "block";
            if ($.browser.msie) {
                try {
                    iframe.height = iframe.Document.body.scrollHeight; //设置iframe在ie下的高度
                }
                catch (e) {
                    iframe.height = iframe.contentWindow.document.documentElement.scrollHeight; //IE9
                }
            }
            else {
                iframe.height = iframe.contentWindow.document.documentElement.scrollHeight; //设置iframe在火狐下高度
            }
        }
    },
   setFrameHeight = function () {
       try {
           window.top.document.getElementById("mainFrame").height = window.top._memoryHeight;
       } catch (e) {
           window.top.document.getElementsById("mainFrame").height = 500;
       }
   }

    return {
        resizeFrame: function () {
            resizeFrame();
        },
    }
}();
